Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounds check some tab GetAt()s #16016

Merged
merged 1 commit into from
Oct 5, 2023
Merged

Bounds check some tab GetAt()s #16016

merged 1 commit into from
Oct 5, 2023

Conversation

zadjii-msft
Copy link
Member

GetAt can throw if the index is out of range. We don't check that in some places. This fixes some of those.

I don't think this will take care of #15689, but it might help?

@@ -2084,7 +2081,7 @@ namespace winrt::TerminalApp::implementation
{
autoPeer.RaiseNotificationEvent(Automation::Peers::AutomationNotificationKind::ActionCompleted,
Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
fmt::format(std::wstring_view{ RS_(L"TerminalPage_PaneMovedAnnouncement_ExistingWindow") }, tabTitle, windowId),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was straight up not right before. It was getting the title of the tab in the current window, at the index of the target tab.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hold up, is there a way to correct this then? Get the actual tab title of the target tab?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probs not trivially. Each TerminalWindow & TerminalPage is pretty agnostic to the existence of other windows at all. maybe if the window that "caught" the moved pane raised the message, it could be done, but 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, since we're still keeping the functionality, I think that won't be a problem for #15159. I'm just trying to avoid a Sev2 affecting our score again.

tabs.InsertAt(to.value(), tab);
_UpdateTabIndices();
}
CATCH_LOG();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do a bounds check here?

@@ -2084,7 +2081,7 @@ namespace winrt::TerminalApp::implementation
{
autoPeer.RaiseNotificationEvent(Automation::Peers::AutomationNotificationKind::ActionCompleted,
Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
fmt::format(std::wstring_view{ RS_(L"TerminalPage_PaneMovedAnnouncement_ExistingWindow") }, tabTitle, windowId),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, since we're still keeping the functionality, I think that won't be a problem for #15159. I'm just trying to avoid a Sev2 affecting our score again.

<comment>{Locked="{0}"}{Locked="{1}"}This text is read out by screen readers upon a successful pane movement. {0} is the name of the tab the pane was moved to. {1} is the name of the window the pane was moved to.</comment>
<comment>{Locked="{0}"}{Locked="{1}"}This text is read out by screen readers upon a successful pane movement. {0} is the name of the tab the pane was moved to. {1} is the name of the window the pane was moved to. Replaced in 1.19 by TerminalPage_PaneMovedAnnouncement_ExistingWindow2</comment>
</data>
<data name="TerminalPage_PaneMovedAnnouncement_ExistingWindow2" xml:space="preserve">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh this requires a localization cycle :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's why I was trying to get this in before 1.19 released 😉

}

_rearranging = false;

if (to.has_value())
if (to.has_value() &&
*to < gsl::narrow_cast<int32_t>(TabRow().TabView().TabItems().Size()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, we're reaching really deep into somebody else to get this. Is that normal?

@@ -2101,7 +2098,7 @@ namespace winrt::TerminalApp::implementation

// Moving the pane from the current tab might close it, so get the next
// tab before its index changes.
if (_tabs.Size() > tabIdx)
if (tabIdx < _tabs.Size())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change in behavior?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why I felt compelled to make it small thing < big thing in the true case. Just felt like a more sane bounds check here

@zadjii-msft zadjii-msft merged commit 5aaddda into main Oct 5, 2023
17 checks passed
@zadjii-msft zadjii-msft deleted the dev/migrie/b/15689-maybe branch October 5, 2023 14:31
DHowett pushed a commit that referenced this pull request Oct 5, 2023
`GetAt` can throw if the index is out of range. We don't check that in
some places. This fixes some of those.

I don't think this will take care of #15689, but it might help?

(cherry picked from commit 5aaddda)
Service-Card-Id: 90731980
Service-Version: 1.18
DHowett pushed a commit that referenced this pull request Oct 5, 2023
`GetAt` can throw if the index is out of range. We don't check that in
some places. This fixes some of those.

I don't think this will take care of #15689, but it might help?

(cherry picked from commit 5aaddda)
Service-Card-Id: 90731981
Service-Version: 1.19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

4 participants